clear
cd "data directory here" 

use wagedata.dta
gen Schooling = 0
replace Schooling = 6 if Education == 1
replace Schooling = 9 if Education == 2
replace Schooling = 12 if Education == 3
replace Schooling = 14 if Education == 4
replace Schooling = 16 if Education == 5

gen Female = 0
replace Female = 1 if Sex == 2
gen Agesq = Age*Age

mat CPI1 = [1,	            1.21351975,	    1.300755622,	1.345278494,	1.375865345]
mat CPI2 = [1.409709968,	1.448486494,	1.492647392,	1.59929415,  	1.690466495]
mat CPI3 = [1.835392064,	2.00669653,	    2.131396769,	2.233699833,	2.373648251]	
mat CPI4 = [2.480023528,	2.602144699,	2.717659834,	2.921858739,	2.945613321]	
mat CPI5 = [3.012171395,	3.134654541,	3.221256957,	3.334464504,	3.454187593]	
mat CPI6 = [3.549341659,	3.628885571,	3.720872359,	3.89480114,	    4.002171847]	
mat CPI7 = [4.119768336,	4.285643184,	4.379394598,	4.436360346,	4.492918872]
mat CPI8 = [4.524682141,	4.568571558,	4.657255328,	4.726030496]

mat CPI = CPI1,CPI2,CPI3,CPI4,CPI5,CPI6, CPI7, CPI8

gen Wage = MonthlyPay/WorkHour
gen lnWage = .


forvalues i = 1980/2015{
local j = `i'-1979
replace Wage = Wage/CPI[1,`j'] if Year == `i'
}

replace lnWage = ln(Wage) 

gen manu =  0 
replace manu = 1 if Industry>=17 & Industry<=37

forvalues i = 1980/2015{
	reg lnWage Female Schooling Age Agesq if Year == `i'
	mat beta`i'=e(b)
}

mat Mincer = J(36,5,.)
mat gender_gap_all = J(36,1,.)
forvalues i = 1980/2015{
	local j = `i'-1979
	forvalues k = 1/5{
	mat Mincer[`j',`k'] = beta`i'[1,`k']
	mat gender_gap_all[`j',1] = beta`i'[1,1]
	}
}
mat list Mincer


forvalues i = 1980/2015{
	reg lnWage Female Schooling Age Agesq if Year == `i' & manu == 1
	mat beta_m`i'=e(b)
	
}
mat Mincer_manu = J(36,5,.)
mat gender_gap_manu = J(36,1,.)
forvalues i = 1980/2015{
	local j = `i'-1979
	forvalues k = 1/5{
	mat Mincer_manu[`j',`k'] = beta_m`i'[1,`k']
	mat gender_gap_manu[`j',1] = beta_m`i'[1,1]
	}
}

mat wage_gap = gender_gap_all, gender_gap_manu
mat list wage_gap

